<?php
namespace App\Http\Controllers\AppApi\Msg;

use App\Services\Main\MsgTalkService;
use Illuminate\Http\Request;

class DetailController extends BaseController
{
    /**
     * 消息窗口
     * 制作者：九哥
     */

    protected $service;

    public function __construct()
    {
        parent::__construct();
        $this->service = new MsgTalkService();
    }

    /**
     * 消息窗口获取
     */
    public function getDetails(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $cate = $request->cate;
        $talkId = $request->talkId;
        if (!$token || !$talkId) { return $this->toJson(-2); }
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $dataArr = $this->service->getDetails($uid,$talkId);
        if (!$dataArr) { return $this->toJson(-3); }
        return $this->toJson(0,$dataArr);
    }

    /**
     * 消息窗口新增
     */
    public function setSend(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $cate = $request->cate;
        $talkId = $request->talkId;
        $quest = $request->quest;
        if (!$token || !$talkId || !$quest) { return $this->toJson(-2); }
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $lastId = $this->service->setSend($uid,$talkId,$quest);
        if (!$lastId) { return $this->toJson(-3); }
        $dataArr = array('id'=>$lastId);
        return $this->toJson(0,$dataArr);
    }
}
